/*
 * Copyright 2010 Christoph Widulle (christoph.widulle@googlemail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */



package com.android1.amarena2d.actions.movement;

import com.android1.amarena2d.actions.base.IntervalAction;
import com.android1.amarena2d.nodes.behavior.ActionTarget;

public class MoveBy extends IntervalAction {

    protected float startPositionX;
    protected float startPositionY;
    protected float deltaX;
    protected float deltaY;

    public MoveBy(float x, float y, float duration) {
        super(duration);
        deltaX = x;
        deltaY = y;
    }

    public static MoveBy $(float x, float y, float duration) {
        /* MoveBy moveBy = checkPooled(MoveBy.class);
        if (moveBy != null)
            return moveBy.reset(x, y, duration);
        else*/
        return new MoveBy(x, y, duration);
    }

    public MoveBy reset(float deltaX, float deltaY, float duration) {
        this.duration = duration;
        this.deltaX = deltaX;
        this.deltaY = deltaY;
        return this;
    }

    @Override
    public void start(ActionTarget target) {
        super.start(target);

        startPositionX = target.getX();
        startPositionY = target.getY();
    }


    @Override
    public void update(float time) {
        target.setXY(startPositionX + deltaX * time, startPositionY + deltaY * time);
    }

    public MoveBy reverse() {
        return MoveBy.$(-deltaX, -deltaY, duration);
    }

    @Override
    public MoveBy copy() {
        return MoveBy.$(deltaX, deltaY, duration);
    }

    /*  public static void createPool(int size) {
        createPool(MoveBy.class, size, new ActionPool.InstanceCreator<MoveBy>() {
            @Override
            public MoveBy newInstance() {
                return new MoveBy(0, 0, 0);
            }
        });
    }*/
}